//Code used for saving/loading players
//May also save/load other things in the future

mob/pc
	proc
		SavePlayer(var/mob/pc/P as mob)
			if(ismob(P))
				if(P.savable)
					var/savefile/F = new("savefiles\\[P.ckey].sav")
					if(P.TurnController)
						P.TurnController.RemoveMob(P)
					var/tmp/TurnController/TC = TurnController
					TurnController = null
					LevelController = null
					P.Write(F)
					TurnController = TC
					LevelController = LevelControllers[z]
				else
					P << "\red Sorry [P], you can't be saved right now."
					return 0
		LoadPlayer(var/mob/pc/P as mob)
			if(ismob(P))
				var/savefile/F = new("savefiles\\[P.ckey].sav")
				P.Read(F)
				players_list += P
				world <<"<font color=[rgb(P.Red,P.Green,P.Blue)]>[P]</font></font> has entered the realm"
				P.UpdateLevelController()
				P.NewTurnController()
		DeletePlayer(var/mob/pc/P as mob)
			fdel("savefiles\\[P.ckey].sav")
		PlayerIsSaved(var/mob/pc/P as mob) //Check if the player has saved before
			if(fexists("savefiles\\[P.ckey].sav"))
				return 1
//Temporary vars to save
	var
		saved_x
		saved_y
		saved_z
//Add on to the default Write() and Read()
	Write(savefile/F)
		saved_x = x
		saved_y = y
		saved_z = z
		..() //store variables
	Read(savefile/F)
		..() //restore variables
		if(saved_z < DUNGEON_INIT )
			Teleport(locate(saved_x,saved_y,saved_z))
		else
			Teleport(locate(36,14,1))